package com.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * @ClassName FileController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/6 10:15
 * @Version 1.0
 **/
@Controller
public class FileController {
    @RequestMapping("upload")
    public String uploadFile(MultipartFile upload) throws IOException {
        System.out.println("springmvc方式的文件上传");
        //要上传的文件目录
        String path ="d:\\";
        //获取文件上传名称
        String filename = upload.getOriginalFilename();
        System.out.println(filename);
        //完成文件上传
        upload.transferTo(new File(path,filename));
        return "success";

    }
}
